-- thor
-- created by wangy
-- 攻击时概率触发技能（雷神之锤）

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,
    -- 触发
    trigger = function(who, prop, arg)
        if who.type ~= OBJECT_TYPE_USER then
            return;
        end

        -- 触发概率增加
        local specialProp = PropM.combine(who, "prop_force_add", prop[1]);
        local rate = prop[3];
        if specialProp[3] > 0 then
            rate = rate + specialProp[3];
        end

        -- 不满足概率
        if DungeonM.getRandSeed("attack_skill") % 1000 >= rate then
            return;
        end

        local skillId = tonumber(prop[2]);
        local skills = SkillM.getSkillTable();
        if not skills[skillId] then
            return;
        end

        -- 目标
        local grid;
        local round = CombatM.getRound();
        if not SkillM.needTarget(skillId) then
            SkillM.apply(who, who, skillId, round);
        else
            for p = 1, DUNGEON_WIDTH * DUNGEON_HEIGHT do
                grid = DungeonM.getGridByPos(p);

                -- 是未死亡的怪物
                if grid:isOpened() and
                   grid:isMonster() and
                   not grid.monster:isDead() then
                    SkillM.apply(who, grid.monster, skillId, round);
                end
            end
        end

        -- 触发特技发动事件
        EventMgr.fire(event.SPECIAL_SKILL_TRIGGER, { propId = prop[1] });
    end,

    record = function(target, prop, path)
        return false;
    end
};
